package com.ruoyi.basis.config;

import com.mashuai.utils.base.MsIocUtils;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: MinioUtils
 * @Author : mashuai
 * @Description: TODO
 */
@Configuration
public class MinioConfig {

    private static String url;

    private static String account;

    private static String password;
    //默认桶名称，可根据文件后缀放入不同的桶中
    private static String defBucketName;

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder().endpoint(url).credentials(account, password).build();
    }

    /**
     * 获取minio对象
     **/
    public static MinioClient getMinioClient() {
        return MsIocUtils.getBean(MinioClient.class);
    }
    /**
     * 获取访问url
     **/
    public static String getUrl() {
        return url;
    }
    /**
     * 获取默认的桶名字
     **/
    public static String getDefBucketName() {
        return defBucketName;
    }

    @Value("${minio.url:127.0.0.1:9000}")
    private void setUrl(String val) {
        this.url = val;
    }

    @Value("${minio.account:admin}")
    private void setAccount(String val) {
        this.account = val;
    }

    @Value("${minio.password:admin123}")
    private void setPassword(String val) {
        this.password = val;
    }

    @Value("${minio.defBucketName:def-bucket}")
    private void setDefBucketName(String val) {
        this.defBucketName = val;
    }


}
